package SecondTry;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 05.12.13
 * Time: 19:30
 * To change this template use File | Settings | File Templates.
 */
public class SquareField extends IField {

    public SquareField(Coordinates measures, Coordinates treasure) throws IncorrectCoordinatesException {
        if (measures.getX()==0 || measures.getY()==0) throw new IncorrectCoordinatesException();
        this.measures = measures;
        this.treasure = treasure;
        if (isNotTreasureCoordinatesCorrect()) throw new IncorrectCoordinatesException();
    }

    @Override
    public boolean isFindTreasure(Coordinates coordinates) {
        return treasure.equals(coordinates);
    }

    @Override
    protected boolean isNotTreasureCoordinatesCorrect() {
        return treasure.isNotInMeasures(measures);
    }

    @Override
    public Coordinates getMeasures() {
        return measures;
    }

    @Override
    public int getSize() {
        return measures.getX()*measures.getY();
    }
}
